﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartSpace.Data;

namespace SsTool.Metadata.Windows
{
    /// <summary>
    /// Interaction logic for DictionaryDataWindow.xaml
    /// </summary>
    public partial class DictionaryDataWindow : Window
    {
        public DictionaryData DictionaryData { get; private set; }

        public DictionaryDataWindow(DictionaryType type)
            : this(type, null)
        {
        }

        public DictionaryDataWindow(DictionaryType type, DictionaryData parent)
        {
            InitializeComponent();

            DictionaryData = new DictionaryData();
            this.DictionaryData.Id = Guid.NewGuid();
            if (parent != null)
            {
                this.DictionaryData.Parent = parent;
                this.DictionaryData.ParentId = parent.Id;
            }

            this.DictionaryData.Type = type;
            this.DictionaryData.TypeId = type.Id;

            this.DataContext = this.DictionaryData;
        }

        private void _ctlBtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            IDataService service = App.Get<IDataService>();
            if (service.SaveDictionaryData(this.DictionaryData))
            {
                DialogResult = true;
            }
        }

        private void _ctlBtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
